package cn.nubia.admin.common.springmvc;

import cn.nubia.admin.common.constant.SystemConstant;
import cn.nubia.admin.common.freemaker.PermissionDirective;
import cn.nubia.admin.sysconfig.service.SysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.view.freemarker.FreeMarkerView;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by Administrator on 2015/6/26.
 */
public class WebFreeMarkerView extends FreeMarkerView {
    public static String CDN_PATH;

    @Override
    protected void exposeHelpers(Map<String, Object> model, HttpServletRequest request) throws Exception {
        model.put("ctx", request.getContextPath());
        model.put("userInfo",WebContext.getCachedUser());
        model.put("refer",WebContext.getRefer());
        model.put("staticHost", SystemConstant.staticHost);
        Object moduleId =WebContext.getAttr(WebContext.MODULE_ID);
        moduleId =moduleId==null?SystemConstant.getDefaultMenuId():moduleId;
        model.put("moduleId", moduleId);
        model.put("permission",new PermissionDirective());
        model.put("currMenu",SystemConstant.getMenu(Integer.valueOf(moduleId.toString())));
        model.put("sysmenus",SystemConstant.menus);

        Map<String,String> map = SpringContextLoader.getBean(SysConfigService.class).getSystemConfigMap();
        for (String s : map.keySet()) {
            model.put(s,map.get(s));
        }
    }
}
